package com.meida.module.bus.provider.controller;

import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.bus.provider.service.BusProductService;
import com.meida.module.product.client.entity.ProdProduct;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
 * 产品控制器
 *
 * @author flyme
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/bus/product/")
public class BusProductController extends BaseController<BusProductService, ProdProduct> {

    @Resource
    BusProductService busProductService;

    @ApiOperation(value = "产品-分页列表", notes = "产品分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return busProductService.pageList(params);
    }

    @ApiOperation(value = "产品-列表", notes = "产品列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return busProductService.listEntityMap(params);
    }

    @ApiOperation(value = "产品-添加", notes = "添加产品")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return busProductService.add(params);
    }

    @ApiOperation(value = "产品-更新", notes = "更新产品")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return busProductService.edit(params);
    }

    @ApiOperation(value = "产品-删除", notes = "删除产品")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return busProductService.delete(params);
    }


    @ApiOperation(value = "产品-详情", notes = "产品详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = true) Long productId) {
        return ResultBody.ok(busProductService.getProductDetail(productId));
    }

    @ApiOperation(value = "商品-上架下架", notes = "商品-上架下架")
    @PostMapping(value = "setOnLineState")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", required = true, value = "主键", paramType = "form"),
            @ApiImplicitParam(name = "onlineState", required = true, value = "显示状态", paramType = "query")
    })
    public ResultBody setOnLineState(@RequestParam(value = "ids") Long[] ids, @RequestParam(value = "onlineState") Integer onlineState) {
        return busProductService.setonLineState(ids, onlineState);
    }


    @ApiOperation(value = "商品-推荐设置", notes = "商品-推荐设置")
    @PostMapping(value = "setRecommend")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", required = true, value = "主键", paramType = "form"),
            @ApiImplicitParam(name = "recommend", required = true, value = "推荐状态", paramType = "query")
    })
    public ResultBody setRecommend(@RequestParam(value = "ids") Long[] ids, @RequestParam(value = "recommend") Integer recommend) {
        return busProductService.setRecommend(ids, recommend);
    }

}
